package com.study.controller;

import com.study.pojo.Book;
import com.study.service.BookService;
import com.study.service.ChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * @Author Miss kun
 * @Date 2020/9/29 19:08
 * @Version 1.0
 */
@Controller
@RequestMapping("/book")
public class BookController {

    @Autowired
    private BookService bookService;

    @Autowired
    private ChapterService chapterService;


    /**
     * 获取指定图书的id和章节id的信息
     * @param bookId
     * @param chapterId
     * @param model
     * @return
     */
    @RequestMapping("/getChapter/{bookId}/{chapterId}")
    public String getChapterById(@PathVariable String bookId, @PathVariable String chapterId, Model model){
        Book bookChapter = bookService.getChapterById(Integer.parseInt(bookId), Integer.parseInt(chapterId));
        model.addAttribute("bookChapter",bookChapter);
        return "chapterText";
    }
}
